package com.pan.controller;


import com.pan.entity.Depository;
import com.pan.entity.Result;
import com.pan.service.DepositoryService;
import com.pan.vo.DepositoryCreateVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/depository")
public class DepositoryController {

    @Resource
    private DepositoryService depositoryService;

    @ResponseBody
    @GetMapping("/getAddress/{id}")
    public Result<String> getDepositoryAddress(@PathVariable Integer id){
        Result<String> result = depositoryService.getAllAddress(id);
        return result;
    }


    @PostMapping("/create")
    @ResponseBody
    public Result createDepository(@CookieValue("adminTicket") String adminTicket,
                                   @RequestBody DepositoryCreateVo depositoryCreateVo
                                   ){
        Result result = depositoryService.insert(adminTicket,depositoryCreateVo);
        return result;
    }

    @ResponseBody
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id){
        Result result = depositoryService.selectById(id);
        return result;
    }

    @ResponseBody
    @GetMapping("/selectByDistrictId/{districtId}/{districtLevel}")
    public Result selectByDistrictId(@PathVariable Integer districtId,
                                     @PathVariable Integer districtLevel){
        Result<List<Depository>> result = depositoryService.selectByAddress(districtId,districtLevel);
        return result;
    }

}
